import re

def get_url_list():
    with open("./url.txt", 'r') as f:
        content = f.read()
        urls = content.split('\n')
    return urls

def filter():
    err_urls = []
    with open("error2.log", 'r', encoding='utf-8') as f:
        content = f.read()
        err_line = content.split('\n')

    for i in err_line:
        #  //MODV6_Cmp_B/MOLT/MOD13A3.006/2001.04.01/MOD13A3.A2001091.h27v05.006.2015142201442.hdf
        x = re.search(r"//.*\.hdf", i)
        if x:
            uri = x.group()
            url = "https://e4ftl01.cr.usgs.gov" + uri
            err_urls.append(url)
        else:
            continue
    return list(set(err_urls))

if __name__ == '__main__':
    print(filter())
    with open('err_url.txt', 'w') as f:
        for i in filter():
            f.write(i)
            f.write('\n')